#include "widget1.h"
#include <QProcess>
#include <QHBoxLayout>
#include <QVBoxLayout>

Widget1::Widget1(QWidget *parent)
    : QWidget(parent)
{
    infoLabel = new QLabel;
    openLabel = new QLabel;
    cmdLineEdit = new QLineEdit;
    commitBut = new QPushButton;
    cancelBut = new QPushButton;

    infoLabel->setText("请输入名称");
    openLabel->setText("打开");
    commitBut->setText("确定");
    cancelBut->setText("取消");

    commitBut->setFixedSize(60, 30);
    cancelBut->setFixedSize(60, 30);

    QHBoxLayout *cmdLayout = new QHBoxLayout;
    cmdLayout->addWidget(openLabel);
    cmdLayout->addWidget(cmdLineEdit);
    QHBoxLayout *butLayout = new QHBoxLayout;
    butLayout->addWidget(commitBut);
    butLayout->addWidget(cancelBut);
    QVBoxLayout *mainLayout = new QVBoxLayout;
    mainLayout->addWidget(infoLabel);
    mainLayout->addLayout(cmdLayout);
    mainLayout->addLayout(butLayout);

    setLayout(mainLayout);

    // 谁发出的信号，发出什么信号，交给谁处理，怎么处理
    connect(commitBut, SIGNAL(clicked()), this,
            SLOT(on_commitBut_clicked()));
    // connect(cancelBut, &QPushButton::clicked, this,
    //         &Widget1::on_cancelBut_clicked);
    connect(cancelBut, &QPushButton::clicked, this, [=](){ this->close();
    });
}




Widget1::~Widget1() {}


void Widget1::on_commitBut_clicked()
{
    QString program = cmdLineEdit->text();
    QProcess *process = new QProcess;
    process->start(program);
}
// void Widget1::on_cancelBut_clicked()
// {
//     this->close();
// }


















